package com.qf2210.group.three.server.controller.liqing;

import com.qf2210.group.three.pojo.Brand;
import com.qf2210.group.three.pojo.Category;
import com.qf2210.group.three.pojo.Good;
import com.qf2210.group.three.server.service.BrandService;
import com.qf2210.group.three.server.service.CategoryService;
import com.qf2210.group.three.server.service.GoodService;
import com.qf2210.group.three.utils.JsonResult;
import com.qf2210.group.three.utils.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Study on the 01
 *
 * @Author: 李青
 * @Date: 2022/12/01/17:25
 * @Description:商品的查询
 */
@RestController
@RequestMapping("/good")
public class GoodController {

    @Autowired
    CategoryService categoryService;
    @Autowired
    BrandService brandService;
    @Autowired
    GoodService goodService;

    /**
     * 查询所有的类别
     *
     * @return JsonResult
     */
    @GetMapping("/allCategorys")
    public JsonResult allCategorys() {
        List<Category> categories = categoryService.list();
        JsonResult jsonResult = new JsonResult();
        jsonResult.setData(categories);
        return jsonResult;
    }

    /**
     * 查询所有的品牌
     *
     * @return JsonResult
     * @Description:参数 品牌id
     */
    @GetMapping("/allBrands/{id}")
    public JsonResult allBrands(@PathVariable("id") Integer bId) {
        List<Brand> brands = brandService.findBrands(bId);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setData(brands);
        return jsonResult;
    }

    /**
     * 分页查看某个类别下的某个品牌的商品
     * @return JsonResult
     * @Description:参数 类别id  品牌id 页码pageNum   页面大小pageSize
     */
    @GetMapping("/{cid}/{bid}")
    public JsonResult goods(@PathVariable("cid") Integer cId, @PathVariable("bid") Integer bId, Page page) {
        Page<Good> goods = goodService.findGoodsWithPage(cId, bId, page);

        JsonResult jsonResult = new JsonResult();
        jsonResult.setData(goods);
        return jsonResult;
    }
}
